<?php
/**
 * 作者: https://gitee.com/miren123
 * 时间: 2022-05-24 10:41:50
 * 描述: 菜单管理
 */

namespace app\admin\controller;

use think\facade\Request;
use app\common\validate\AdminMenuValidate;
use app\common\validate\AdminRoleValidate;
use app\common\validate\AdminUserValidate;
use app\common\service\AdminMenuService;
use app\common\service\AdminUserService;
use hg\apidoc\annotation as Apidoc;

/**
 * @Apidoc\Title("菜单管理")
 * @Apidoc\Group("adminAuth")
 * @Apidoc\Sort("10")
 */
class AdminMenu
{
    /**
     * @Apidoc\Title("菜单列表")
     * @Apidoc\Header(ref="headerAdmin")
     * @Apidoc\Returned(ref="returnPaging"),
     * @Apidoc\Returned("list", type="array", desc="树形列表",
     *     @Apidoc\Returned(ref="app\common\model\AdminMenuModel\list")
     * )
     */
    public function list()
    {
        $data['list'] = AdminMenuService::tree();

        return success($data);
    }

    /**
     * @Apidoc\Title("菜单信息")
     * @Apidoc\Header(ref="headerAdmin")
     * @Apidoc\Param(ref="app\common\model\AdminMenuModel\id")
     * @Apidoc\Returned(ref="app\common\model\AdminMenuModel\info")
     */
    public function info()
    {
        $param['admin_menu_id'] = Request::param('admin_menu_id/d', '');

        validate(AdminMenuValidate::class)->scene('info')->check($param);

        $data = AdminMenuService::info($param['admin_menu_id']);

        if ($data['is_delete'] == 1) {
            exception('菜单已被删除：' . $param['admin_menu_id']);
        }

        return success($data);
    }

    /**
     * @Apidoc\Title("菜单添加")
     * @Apidoc\Method("POST")
     * @Apidoc\Header(ref="headerAdmin")
     * @Apidoc\Param(ref="app\common\model\AdminMenuModel\add")
     */
    public function add()
    {
        $param['menu_pid']  = Request::param('menu_pid/d', 0);
        $param['menu_name'] = Request::param('menu_name/s', '');
        $param['menu_path']  = Request::param('menu_path/s', '');
        $param['is_menu']  = Request::param('is_menu/d', 0);
        $param['menu_component']  = Request::param('menu_component/s', '');
        $param['menu_url']  = Request::param('menu_url/s', '');
        $param['menu_sort'] = Request::param('menu_sort/d', 200);
        $param['add_list'] = Request::param('add_list/b', false);
        $param['add_info'] = Request::param('add_info/b', false);
        $param['add_add']  = Request::param('add_add/b', false);
        $param['add_edit'] = Request::param('add_edit/b', false);
        $param['add_dele'] = Request::param('add_dele/b', false);

        validate(AdminMenuValidate::class)->scene('add')->check($param);

        $data = AdminMenuService::add($param);

        return success($data);
    }

    /**
     * @Apidoc\Title("菜单修改")
     * @Apidoc\Method("POST")
     * @Apidoc\Header(ref="headerAdmin")
     * @Apidoc\Param(ref="app\common\model\AdminMenuModel\edit")
     */
    public function edit()
    {
        $param['admin_menu_id'] = Request::param('admin_menu_id/d', '');
        $param['menu_pid']      = Request::param('menu_pid/d', 0);
        $param['menu_name']     = Request::param('menu_name/s', '');
        $param['menu_path']  = Request::param('menu_path/s', '');
        $param['is_menu']  = Request::param('is_menu/d', 0);
        $param['menu_component']  = Request::param('menu_component/s', '');
        $param['menu_url']      = Request::param('menu_url/s', '');
        $param['menu_sort']     = Request::param('menu_sort/d', 200);
        $param['add_list']      = Request::param('add_list/b', false);
        $param['add_info']      = Request::param('add_info/b', false);
        $param['add_add']       = Request::param('add_add/b', false);
        $param['add_edit']      = Request::param('add_edit/b', false);
        $param['add_dele']      = Request::param('add_dele/b', false);
        $param['edit_list']     = Request::param('edit_list/b', false);
        $param['edit_info']     = Request::param('edit_info/b', false);
        $param['edit_add']      = Request::param('edit_add/b', false);
        $param['edit_edit']     = Request::param('edit_edit/b', false);
        $param['edit_dele']     = Request::param('edit_dele/b', false);

        validate(AdminMenuValidate::class)->scene('edit')->check($param);

        $data = AdminMenuService::edit($param);

        return success($data);
    }

    /**
     * @Apidoc\Title("菜单删除")
     * @Apidoc\Method("POST")
     * @Apidoc\Header(ref="headerAdmin")
     * @Apidoc\Param(ref="app\common\model\AdminMenuModel\dele")
     */
    public function dele()
    {
        $param['admin_menu_id'] = Request::param('admin_menu_id/d', '');

        validate(AdminMenuValidate::class)->scene('dele')->check($param);

        $data = AdminMenuService::dele($param['admin_menu_id']);

        return success($data);
    }

    /**
     * @作者 糜家智
     * @时间 2022-05-01
     * @return 是否菜单
     */
    public function menu(){

      $param['admin_menu_id'] = Request::param('admin_menu_id/d', '');
      $param['is_menu']       = Request::param('is_menu/d', 0);

      validate(AdminMenuValidate::class)->scene('menu')->check($param);

      $data = AdminMenuService::menu($param);

      return success($data);

    }

    /**
     * @Apidoc\Title("菜单是否禁用")
     * @Apidoc\Method("POST")
     * @Apidoc\Header(ref="headerAdmin")
     * @Apidoc\Param(ref="app\common\model\AdminMenuModel\disable")
     */
    public function disable()
    {
        $param['admin_menu_id'] = Request::param('admin_menu_id/d', '');
        $param['is_disable']    = Request::param('is_disable/d', 0);
        halt($param);

        validate(AdminMenuValidate::class)->scene('disable')->check($param);

        $data = AdminMenuService::disable($param);

        return success($data);
    }

    /**
     * @Apidoc\Title("菜单是否无需权限")
     * @Apidoc\Method("POST")
     * @Apidoc\Header(ref="headerAdmin")
     * @Apidoc\Param(ref="app\common\model\AdminMenuModel\unauth")
     */
    public function unauth()
    {
        $param['admin_menu_id'] = Request::param('admin_menu_id/d', '');
        $param['is_unauth']     = Request::param('is_unauth/d', 0);

        validate(AdminMenuValidate::class)->scene('unauth')->check($param);

        $data = AdminMenuService::unauth($param);

        return success($data);
    }

    /**
     * @Apidoc\Title("菜单是否无需登录")
     * @Apidoc\Method("POST")
     * @Apidoc\Header(ref="headerAdmin")
     * @Apidoc\Param(ref="app\common\model\AdminMenuModel\unlogin")
     */
    public function unlogin()
    {
        $param['admin_menu_id'] = Request::param('admin_menu_id/d', '');
        $param['is_unlogin']    = Request::param('is_unlogin/d', 0);

        validate(AdminMenuValidate::class)->scene('unlogin')->check($param);

        $data = AdminMenuService::unlogin($param);

        return success($data);
    }

}
